<?php 
$cat_id = $_GET['cat_id'];
$conn = mysql_connect('127.0.0.1','root','root');
mysql_query('use blog',$conn);
mysql_query('set names utf8',$conn);


//echo $sql;
//如果cat_id 不是数字
if(!is_numeric($cat_id)){
	echo "栏目错误";
	exit();
}

//如果栏目下有文章,不能删除
$sql = "select count(*) from art where cat_id=$cat_id";//6
$rs = mysql_query($sql,$conn);
$row = mysql_fetch_row($rs); 
if($row[0]!=0){
	echo '栏目下面有文章,不能删除';
	exit();
}

//判断该栏目是否存在
$sql = "select count(*) from cat where cat_id=$cat_id";
$rs = mysql_query($sql,$conn);
$row = mysql_fetch_row($rs);
if($row[0]==0){
	echo '栏目不存在';
	exit();
}

$sql = "delete from cat where cat_id=$cat_id";
$rs = mysql_query($sql,$conn);
if($rs){
	echo "删除成功";
}else{
	echo "删除岔纰了,原因:".mysql_error();
}
